<template>
  <div class="ratingselect">
    <div class="ratingtype">
      <span class="block all" @click="select(2, $event)" :class="{active: selectType===2}">{{desc.all}}<span class="count">{{ratings.length}}</span></span>
      <span class="block positive" @click="select(0, $event)" :class="{active: selectType===0}">{{desc.positive}}<span class="count">{{positive.length}}</span></span>
      <span class="block negative" @click="select(1, $event)" :class="{active: selectType===1}">{{desc.negative}}<span class="count">{{negative.length}}</span></span>
    </div>
    <div class="switch">
      <span class="icon-check_circle" @click="toogleContent($event)" :class="{on: onlyContent===true}"></span>
      <span class="text">只看有内容的评价</span>
    </div>
    <div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">

const ALL = 2
const POSITIVE = 0
const NEGATIVE = 1

export default {
  name: 'ratingselect',
  props: {
    ratings: {
      type: Array,
      default() {
        return []
      },
    },
    selectType: {
      type: Number,
      default: ALL,
    },
    onlyContent: {
      type: Boolean,
      default: true,
    },
    desc: {
      type: Object,
      default() {
        return {
          all: '全部',
          positive: '满意',
          negative: '不满意',
        }
      },
    },
  },
  methods: {
    select(selType, event) {
      if (!event._constructed) return
      this.$emit('select-type-change', selType)
    },
    toogleContent(event) {
      if (!event._constructed) return
      this.$emit('content-toogle')
    },
  },
  computed: {
    positive() {
      return this.ratings.filter((rating) => {
        return rating.rateType === POSITIVE
      })
    },
    negative() {
      return this.ratings.filter((rating) => {
        return rating.rateType === NEGATIVE
      })
    },
  },
}
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "../../common/stylus/mixin"

  .ratingselect
    .ratingtype
      padding: 18px 0
      margin: 0 18px
      border-1px(rgba(7, 17, 27, 0.2))
      font-size: 0px
      .block
        display: inline-block
        padding: 8px 12px
        margin-right: 8px
        border-radius: 1px
        font-size: 12px
        color: rgb(77, 85, 93)
        background: rgba(0, 160, 220, 0.2)
        .count
          margin-left: 6px
          font-size: 8px
        &.active
          background: rgba(0, 160, 220, 1)
          color: #fff
        &.negative
          background: rgba(77, 85, 93, 0.2)
          .count
            margin-left: 6px
            font-size: 8px
          &.active
            background: rgba(77, 85, 93, 1)
            color: #fff
    .switch
      padding: 12px 18px
      line-height: 24px
      border-1px(rgba(7, 17, 27, 0.2))
      color: rgb(147, 153, 159)
      font-size: 0
      .icon-check_circle
        display: inline-block
        vertical-align: top
        font-size: 24px
        margin-right: 4px
        &.on
          color: #00c850
      .text
        display: inline-block
        font-size: 12px

</style>
